<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>CODE</title>
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/aes.js" type="text/javascript"></script>
<script src="js/api.js" type="text/javascript"></script>
<script src="js/bootstrap.min.js" type="text/javascript"></script>
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="to_json_files/font-awesome.min.css" rel="stylesheet">
<link href="to_json_files/base.css" rel="stylesheet">
<style type="text/css">
    body{width: 100%;font-family: '微软雅黑';}
    #showJson{
    	text-align: left;
    }
</style>
<script type="text/javascript">
$(document).ready(function() {
	$.get("menu.html",function(data){
		$("#menuDiv").html(data);
	})
	
    // add
    $("#addBtn").on('click', function(){
    	if($("#codeDesc").val() == '') {
    		alert("描述不能为空");
    		return;
    	}
        var bodyData = '{"rCode":"'+$("#module").val()+$("#errorType").val()+'","codeDesc":"'+$("#codeDesc").val()+'"}';
        var tbody = $("#js-tbody");
        $("<tr><td colspan='3' style='text-align: center;'>加载中...</td></tr>").appendTo(tbody);
        API.post('/api/account/code',bodyData,function(data,textStatus){
        	var codeData = data.data;
       		tbody.html('');
       		$('<tr><td>'+codeData.rCode+'</td><td>'+codeData.codeDesc+'</td></tr>')
       		.appendTo(tbody);
        },function(xmlHttpRequest, textStatus, errorThrown){
            console.log(xmlHttpRequest); 
            console.log(textStatus); 
            console.log(errorThrown); 
        });
    });
    
    // query
    $("#queryBtn").on('click', function(){
        var bodyData = '{"rCode":"'+$("#module").val()+$("#errorType").val()+'","codeDesc":"'+$("#codeDesc").val()+'"}';
        var tbody = $("#js-tbody");
        $("<tr><td colspan='3' style='text-align: center;'>加载中...</td></tr>").appendTo(tbody);
        API.post('/api/account/codes',bodyData,function(data,textStatus){
        	tbody.html('');
        	if(data.data.length == 0) {
        		$("<tr><td colspan='3' style='text-align: center;'>暂无</td></tr>").appendTo(tbody);
        		return;
        	}
        	console.debug(data);
        	for(var i = 0; i < data.data.length; i ++) {
	        	var codeData = data.data[i];
	        	console.debug(codeData);
	       		//$('<tr><td>'+codeData.rCode+'</td><td>'+codeData.codeDesc+'</td><td><a href="JavaScript:deleteCode('+codeData.rcId+');">删除</a></td></tr>')
	       		$('<tr><td>'+codeData.rCode+'</td><td>'+codeData.codeDesc+'</td></tr>').appendTo(tbody);
        	}
        },function(xmlHttpRequest, textStatus, errorThrown){
            console.log(xmlHttpRequest); 
            console.log(textStatus); 
            console.log(errorThrown); 
        });
    });
    
});

function deleteCode(rcId) {
	var bodyData = '{}';
	API.delete('/api/account/code/'+rcId,bodyData,function(data,textStatus){
		$("#queryBtn").click();
    },function(xmlHttpRequest, textStatus, errorThrown){
        console.log(xmlHttpRequest); 
        console.log(textStatus); 
        console.log(errorThrown); 
    });
}
</script>
</head>
<body>
<div style="padding: 10px;" id="menuDiv"></div>
<div class="col-sm-9 col-md-10 main text-center">
    <p class="visible-xs">
        <button type="button" class="btn btn-primary btn-xs"
            data-toggle="offcanvas">
            <i class="glyphicon glyphicon-chevron-left"></i>
        </button>
    </p>
	<input class="form-control" id="baseUrl" type="text" placeholder="接口BaseUrl" value="http://192.168.10.212" style="margin: 20px;" />
		<div class="table-responsive">
        <form class="form-horizontal" role="form"
            action="" method="post" enctype="multipart/form-data" onsubmit="return false;">
            
            <fieldset>
                <div class="form-group">
                    <label class="col-sm-2 control-label">模块</label>
                    <div class="col-sm-2">
                        <select id="module" class="form-control">
							<option value='A'>A - 用户</option>
							<option value='E'>E - 员工</option>
							<option value='R'>R - 角色权限</option>
							<option value='N'>N - 通知</option>
							<option value='M'>M - 物资</option>
							<option value='O'>O - 运营</option>
                        </select>
                    </div>
                </div>
            </fieldset>
            
            <fieldset style="display: none;">
                <div class="form-group">
                    <label class="col-sm-2 control-label">错误码类型</label>
                    <div class="col-sm-2">
                       <select id="errorType" class="form-control">
							<!-- <option value='1'>参数校验</option> -->
							<option value='2'>业务处理</option>
                        </select>
                    </div>
                </div>
            </fieldset>

            <fieldset>
                <div class="form-group">
                    <label class="col-sm-2 control-label">CODE描述</label>
                    <div class="col-sm-5">
                        <textarea class="form-control" id="codeDesc" rows="5" placeholder="请详细描述,最好写上解决方案."></textarea>
                    </div>
                </div>
            </fieldset>
            
            
            <fieldset>
                <div class="form-group">
                    <label class="col-sm-2 control-label"></label>
                    <div class="col-sm-5">
                        <input type="button" id="queryBtn" class="col-sm-3 btn btn-primary" style="margin:0px 10px;" value="搜索">
                        <input type="button" id="addBtn" class="col-sm-3 btn btn-primary" value="添加">
                    </div>
                </div>
			</fieldset>
            
            
            <fieldset style="margin-top: 20px;">
                <div class="form-group">
                    <label class="col-sm-2 control-label">返回</label>
                    <div class="col-sm-8">
                        <table class="table table-hover table-bordered table_width">
				        <thead>
				        <tr>
				            <td class="w5">CODE</td>
				            <td class="w80">CODE描述</td>     
				            <!-- <td class="w5">操作</td> -->
				        </tr>
				        </thead>
				        <tbody id="js-tbody">
				        </tbody>
				    </table>
                    </div>
                </div>
            </fieldset>

			</form>
			
    </div>

</div>

</body>
</html>